<script lang="ts" setup>
  import { reactive } from 'vue';
  // import * as mqtt from "mqtt"
  const mqtt = require('mqtt');
  console.log('mqtt: ', mqtt);

  let datas = reactive<any>(null);
  datas.url = 'http://master.10000ss.cn:18083';

  const connection = mqtt.connect('mqtt://test.mosquitto.org');
  connection.on('connect', function () {
    connection.subscribe('presence', function (err) {
      if (!err) {
        connection.publish('presence', 'Hello mqtt');
      }
    });
  });

  connection.on('message', function (topic, message) {
    // message is Buffer
    console.log(message.toString());
    connection.end();
  });
</script>

<template>
  <view> 页面模板,新建pages,将此页面内容复制粘贴到新建.vue文件 </view>
</template>
<style lang="scss" scoped></style>
